<?php
//include "config/koneksi.php";
//include "class/toko.php";
include "class/user.php";


if (ISSET($_POST["registrasi_member"]) && $_POST['nama_toko']!="" && $_POST['alamat']!="" && $_POST['kota']!="" && $_POST['kodepos']!="" && $_POST['telp']!=""
&& $_POST['email']!="" && $_POST['nama_bank']!="" && $_POST['cabang']!="" && $_POST['atas_nama']!="" && $_POST['rek']!="" && $_POST['deskripsi_toko']!=""
&& $_POST['password1']!="" && $_POST['password2']!=""){
	
		if ($_POST['password1'] == $_POST['password2'] ){
	
			$User_Dao = new User_Dao();
			if($User_Dao->cek_email($_POST['email'])==true){
	
				$user=new User();
				$user->email = $_POST['email'];
				$user->password = $_POST['password1'];
				$user->level = "toko";
				$passmd5=md5($user->password);
				//echo $user->email;
				$User_Dao->add($user);
				
				$user2 = $User_Dao->get_email($_POST['email']);
			
				$Toko_Dao = new Toko_Dao();
				$toko=new Toko();
				$toko->id_toko = $user2->id;
				$toko->nama_toko = $_POST['nama_toko'];
				$toko->alamat = $_POST['alamat'];
				$toko->kota = $_POST['kota'];
				$toko->kodepos = $_POST['kodepos'];
				$toko->telp = $_POST['telp'];
				$toko->email = $user2->email;
				$toko->nama_bank = $_POST['nama_bank'];
				$toko->cabang = $_POST['cabang'];
				$toko->atas_nama = $_POST['atas_nama'];
				$toko->rek = $_POST['rek'];
				$toko->deskripsi_toko = $_POST['deskripsi_toko'];
				$toko->tgl_daftar = $_POST['tgl_daftar'];
				$Toko_Dao->add($toko);
				echo "<script>alert('Registrasi berhasil. Silahkan login menggunakan email dan password yang Anda daftarkan.!');
				location.href='?menu=formlogin';
				</script>";
				
						
		} else { echo "<script>alert('Peringatan : Email tidak tersedia. Silahkan pilih email yang lain');</script>";}
	} else { echo "<script>alert('Peringatan : Kedua password tidak cocok!');</script>";}
			
	} 
?>
<html>
<head>
  <link rel="stylesheet" href="css/val.css" type="text/css" />
<script type="text/javascript" src="js/jquery-1.4.js"></script>
  <script type="text/javascript" src="js/jquery.validate.js"></script>
  <script type="text/javascript">
		$(document).ready(function() {
			$("#form1").validate({
				rules: {
				nama_toko: "required",
				alamat: "required",
				kota: "required",
				kodepos: {
	          		required: true,
					number: true,
					minlength: 5
          		},
				telp: {
	          		required: true,
					number: true
          		},
          		email: {				
					required: true,
					email: true
				},
				nama_bank: "required",
          		cabang: "required",
          		atas_nama: "required",
          		rek: {
	          		required: true,
					number: true
          		},
				deskripsi_toko: "required",
				},
			
      	messages: { 
			    nama_toko: {
				    required: '. Nama harus di isi'
			    },
			    alamat: {
				    required: '. Alamat harus di isi'
			    },
				kota: {
				    required: '. Kota harus di isi'
			    },
			    kodepos: {
				    required: '. Kode Pos harus di isi',
				    minlength: '. Kode Pos harus 5 Angka',
				    number  : '. Hanya boleh di isi Angka'
			    },
		      	telp: {
				    required: '. No Telp / Hp harus di isi',
				    number  : '. Hanya boleh di isi Angka'
			    },
			    email: {
				    required: '. Email harus di isi',
				    email   : '. Email harus valid'
			    },
			    nama_bank: {
				    required: '. Nama Bank di isi'
			    },
			    cabang: {
				    required: '. Cabang Bank harus di isi'
			    },
			    atas_nama: {
				    required: '. Atas Nama harus di isi'
			    },
			    rek: {
				    required: '. No Rekening harus di isi',
				    number  : '. Hanya boleh di isi Angka'
			    },
				deskripsi_toko: {
				    required: '. Deskripsi Toko harus di isi'
			    },
			   },
         
         success: function(label) {
            label.text('OK!').addClass('valid');
         }
			});
		});
	</script>
<title>Input Toko</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div class="form-div">
	<form id= "form1" method="post" action="?menu=input_toko" >
	<input type="hidden" name="registrasi_member" >
	<input type="hidden" name="tgl_daftar" value=<?php echo date("Y-m-d"); ?>>
	<table width="95%" border="0" align="center">
    <tr valign="top"> 
      <td colspan="2"></td><td height="19"><font size="2" face="tahoma">Masukkan Data Anda :<font color="#FFFFFF"> </font></font></td>
    </tr>
	<tr valign="top"> 
				  <td width="21%" align="center"> <div align="left"><font size="2" face="tahoma">Nama</font></div></td>
				  <td width="1%">:</td>
				  <td width="78%" align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <input name="nama_toko" type="text" id="nama_toko" size="30" maxlength="50">
				  </font></div></td>
			</tr>
	<tr valign="top"> 
				  <td align="center"> <div align="left"><font size="2" face="tahoma">Alamat</font></div></td>
				  <td>:</td>
				  <td align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <textarea name="alamat" cols="40" rows="4" id="alamat"></textarea>
				  </font></div></td>
			</tr>
	<tr valign="top"> 
				  <td width="21%" align="center"> <div align="left"><font size="2" face="tahoma">Kota</font></div></td>
				  <td width="1%">:</td>
				  <td width="78%" align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <input name="kota" type="text" id="kota" size="30" maxlength="50">
				  </font></div></td>
			</tr>
	<tr valign="top"> 
				  <td width="21%" align="center"> <div align="left"><font size="2" face="tahoma">Kodepos</font></div></td>
				  <td width="1%">:</td>
				  <td width="78%" align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <input name="kodepos" type="text" id="kodepos" size="30" maxlength="50">
				  </font></div></td>
			</tr>
	<tr valign="top"> 
				  <td width="21%" align="center"> <div align="left"><font size="2" face="tahoma">Telepon / HP</font></div></td>
				  <td width="1%">:</td>
				  <td width="78%" align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <input name="telp" type="text" id="telp" size="30" maxlength="50">
				  </font></div></td>
			</tr>
	<tr valign="top"> 
				  <td align="center"> <div align="left"><font size="2" face="tahoma">Deskripsi Toko</font></div></td>
				  <td>:</td>
				  <td align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <textarea name="deskripsi_toko" cols="40" rows="4" id="deskripsi_toko"></textarea>
				  </font></div></td>
			</tr>
		<tr>
			<td colspan=2 align=center></td><td><font face=tahoma size=2><br><br>Informasi Rekening Anda</font></td>
			</tr>
			<tr valign="top"> 
				  <td width="21%" align="center"> <div align="left"><font size="2" face="tahoma">Nama Bank</font></div></td>
				  <td width="1%">:</td>
				  <td width="78%" align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <input name="nama_bank" type="text" id="nama_bank" size="30" maxlength="30">
				  </font></div></td>
			</tr>
			<tr valign="top"> 
				  <td width="21%" align="center"> <div align="left"><font size="2" face="tahoma">Cabang</font></div></td>
				  <td width="1%">:</td>
				  <td width="78%" align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <input name="cabang" type="text" id="cabang" size="30" maxlength="50">
				  </font></div></td>
			</tr>
			<tr valign="top"> 
				  <td width="21%" align="center"> <div align="left"><font size="2" face="tahoma">Atas Nama</font></div></td>
				  <td width="1%">:</td>
				  <td width="78%" align="center"> <div align="left"> <font size="2" face="tahoma"> 
				  <input name="atas_nama" type="text" id="atas_nama" size="30" maxlength="50">
                  </font></div></td>
			</tr>
			<tr valign="top"> 
				  <td align="center"><div align="left"><font size="2" face="tahoma">No. Rekening Bank</font></div></td>
				  <td><div align="left">:</div></td>
				  <td align="center"><div align="left"><font size="2" face="tahoma"> 
				  <input name="rek" type="text" id="rek" maxlength=20>
				  </font></div></td>
			</tr>
			<tr>
			<td colspan=2 align=center></td><td><font face=tahoma size=2><br><br>Data Login</font></td>
			</tr>
			</tr>
				<tr valign="top"> 
				  <td align="center"> <div align="left"><font size="2" face="tahoma">E-Mail</font></div></td>
				  <td>:</td>
				  <td align="center"> <div align="left"> <font size="2" face="tahoma"> 
					  <input name="email" type="text" id="email" size="50" maxlength="50">
					   <br><br>
					  Ex : abcde@gmail.com <i><u>(Sebagai Username Anda)</u></i>
					  </font></div></td>
				</tr>
			<tr valign="top"> 
				  <td align="center"><div align="left"><font size="2" face="tahoma">Password</font></div></td>
				  <td><div align="left">:</div></td>
				  <td align="center"><div align="left"><font size="2" face="tahoma"> 
					  <input name="password1" type="password" id="password1">
					  </font></div></td>
				</tr>
			<tr valign="top"> 
				  <td align="center"><div align="left"><font size="2" face="tahoma">Password(Retype)</font></div></td>
				  <td><div align="left">:</div></td>
				  <td align="center"><div align="left"><font size="2" face="tahoma"> 
					  <input name="password2" type="password" id="password2">
					  </font></div></td>
				</tr>
            <tr valign="top"> 
				  <td colspan="2"></td><td height="21">
				  <label>
				  <input type="submit" name="submit" value="Simpan">
				  </label></td>
			</tr>
    </table></div>
	</form>
</body>
</html>

